% 2.1
figure(1);
freqs = [    10      20      30      50      80     120     200     300     400];
amps =  [0.9598  0.8373 0.6382 9.653e-5  1.5241  4.5286 12.4759 24.4854 34.2013];
plot(freqs,amps);
xlabel('frequency');
ylabel('amplitudes');
% 2.2
impuls = [10.2159 -19.4317 10.2159 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
figure(2);
subplot(1,2,1);
stem(1:size(impuls,2),impuls);
subplot(1,2,2);
%figure;
plotfreq(impuls);
%plotfreq(impuls,'LOG');

% 2.2 enhanced
t=0.1*pi;
lineqs = [1 1      1        1       ;
          1 cos(t) cos(2*t) cos(3*t);
          0 sin(t) sin(2*t) sin(3*t);
          0 1      1        1       ];
rhs = [1; 0; 0; 0];
answers=lineqs\rhs; % waardes van de gains.

impuls2 = [9.2159 -16.5296 7.3138 1.0000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
figure(3);
subplot(1,2,1);
stem(1:size(impuls2,2),impuls2);
subplot(1,2,2);
%figure;
plotfreq(impuls2);
%plotfreq(impuls2,'LOG');

%2.3
x=0:63;
C1=0.15-0.3162i;
C2=0.15+0.3162i;
de=C1*(0.9487i).^x + C2*(-0.9487i).^x;
unit = zeros(1,64);
unit(1) = 1;
direct = filter([0.3 0.6 0.3],[1 0 0.9],unit);
figure(3);
subplot(1,2,1);
stem(x,direct);
ylabel('y(n)');
xlabel('n');
title('direct');
subplot(1,2,2);
%figure;
stem(x,de);
ylabel('y(n)');
xlabel('n');
title('difference equation');

%2.4
figure(4);
unit = zeros(1,1000);
unit(1) = 1;
direct = filter([0.3 0.6 0.3],[1 0 0.9],unit);
plotfreq(direct);

%2.5
de_impulse_response = [0.3000 0.6000 0.0300 -0.5400 -0.0270 0.4860 0.0243 -0.4374 -0.0219 0.3937 0.0197 -0.3543 -0.0177 0.3189 0.0159 -0.2870 -0.0143 0.2583 0.0129 -0.2325 -0.0116 0.2092 0.0105 -0.1883 -0.0094 0.1695 0.0085 -0.1525 -0.0076 0.1373 0.0069 -0.1235 -0.0062 0.1112 0.0056 -0.1001 -0.0050 0.0901 0.0045 -0.0811 -0.0041 0.0729 0.0036 -0.0657 -0.0033 0.0591 0.0030 -0.0532 -0.0027 0.0479 0.0024];
figure(5);
stem(1:size(de_impulse_response,2),de_impulse_response);
